<?  
	$title="Upload Display Picture"; 
	$pageid="2";
	$accessid="a00";

	require("required/dbconnect.php"); 
	require("required/function.php");
	require("required/header.php");
	

	
	$errormsg="";
	$uploaddir = "../images/watermark"; 
	$allowed_ext = "png, PNG"; 
	$max_size = "2000000"; 
	$ok="";
	
	if(is_uploaded_file($_FILES['file']['tmp_name'])==true)
	{
		$extension = pathinfo($_FILES['file']['name']);
		$extension = $extension['extension'];
		$allowed_paths = explode(", ", $allowed_ext);
		for($i = 0; $i < count($allowed_paths); $i++)
		{
			if ($allowed_paths[$i] == "$extension")
			{
				$ok = "1";
			}
		}
	
		// Check File Size
		if ($ok == "1") 
		{
			if($_FILES['file']['size'] > $max_size)
			{
				$errormsg="file size too big, must smaller than 2MB";
				$back="<input type=button value=\"Back\" onclick=\"history.go(-1)\" class=button>";
				echo "line 50";
			}
			else
			{
				if(is_uploaded_file($_FILES['file']['tmp_name']))
				{
					$tempfile=getimagesize($_FILES['file']['tmp_name']);
					
					$width=$tempfile[0];
					$height=$tempfile[1];
					
					
					
					$newname="watermark.png";
					move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.'/'.$newname);
							
					$errormsg="watermark update successfully!";
					$success="1";
					$back="<input type=button value=\"Back\" onclick=\"window.open('sys_layout.php','_self')\" class=button>";
						
					
				}
			}
				
		}
		else 
		{
			$errormsg="Invalid format, must in .PNG";
			$success="0";
			$back="<input type=button value=\"Back\" onclick=\"history.go(-1)\" class=button>";
		}
	
	}
	else
	{
		$errormsg="You didn't choose a picture to upload or the picture size is too big";
		$back="<input type=button value=\"Back\" onclick=\"history.go(-1)\" class=button>";
	}

	
	
?>
<table width="95%" class="solidborder" cellpadding="2" cellspacing="1">

	<td class="solidborder" width="84%" align="left" valign="top">
		<table width="100%">
		  <tr>
			<td height="20" colspan="7" align="left" style="background: url(images/tbl_th.png);color:#FFFFFF" ><font color="#FFFFFF"><strong>Upload Watermark</strong></font> </td>
		  </tr>
		  <tr>
			<td align="center"><br><br>
			<font color=red><?= $errormsg ?></font><br><br>
			<?= $back ?><br><br>
			</td>
		 </tr>
		</table>
	</td>
 </table>
<? require("required/footer.php"); ?>
      
  